<?php
	class nguoidungdb
	{
		public function Add($TenNguoiDung, $TenDangNhap, $MatKhau, $DiaChi, $Email, $DienThoai, $QuyenHan, $Khoa)
		{
			$sql = "INSERT INTO 
			`tbl_nguoidung`(`TenNguoiDung`, `TenDangNhap`, `MatKhau`, `DiaChi`, `Email`, `DienThoai`, `QuyenHan`, `Khoa`) 
			VALUES ('$TenNguoiDung', '$TenDangNhap', '$MatKhau','$DiaChi', '$Email', '$DienThoai', $QuyenHan, $Khoa)";
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
		
		public function Delete($MaNguoiDung)
		{
			$sql = "DELETE FROM `tbl_nguoidung` WHERE MaNguoiDung = $MaNguoiDung";
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
		
		public function Update($MaNguoiDung, $TenNguoiDung, $DiaChi, $Email, $DienThoai)
		{
			$sql = "UPDATE `tbl_nguoidung` 
					SET `TenNguoiDung`='$TenNguoiDung', 
						`DiaChi`='$DiaChi',
						`Email`='$Email',
						`DienThoai`='$DienThoai'
					WHERE `MaNguoiDung`=$MaNguoiDung";
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
		
		public function GetList($MaNguoiDung, $TenNguoiDung, $TenDangNhap, $MatKhau, $DiaChi, $Email, $DienThoai)
		{
			$sql = "SELECT * FROM `tbl_nguoidung` WHERE 1";
			if($MaNguoiDung != 0)
				$sql .= " AND MaNguoiDung = $MaNguoiDung";
			
			if($TenNguoiDung != "")
				$sql .= " AND TenNguoiDung LIKE '%$TenNguoiDung%'";
			
			if($TenDangNhap != "")
				$sql .= " AND TenDangNhap = '$TenDangNhap'";
				
			if($MatKhau != "")
				$sql .= " AND MatKhau = '$MatKhau'";
				
			if($DiaChi != "")
				$sql .= " AND DiaChi = '$DiaChi'";
				
			if($Email != "")
				$sql .= " AND Email = '$Email'";
				
			if($DienThoai != "")
				$sql .= " AND DienThoai = '$DienThoai'";
			$data = new dataservice();
			return $data->ExecuteQuery($sql);
		}
		
		public function ChangePass($MaNguoiDung, $MatKhau)
		{
			$sql = "UPDATE `tbl_nguoidung` 
					SET `MatKhau`='$MatKhau'
					WHERE `MaNguoiDung`=$MaNguoiDung";
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
		
		public function Active($MaNguoiDung, $QuyenHan, $Khoa)
		{
			$sql = "UPDATE `tbl_nguoidung` 
					SET `QuyenHan`='$QuyenHan',
						`Khoa` = '$Khoa'
					WHERE `MaNguoiDung`=$MaNguoiDung";
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
	}
?>